package com.fy.controller;

import com.fy.common.annotation.GlobalInterceptor;
import com.fy.pojo.dto.file.FileShareDTO;
import com.fy.pojo.vo.file.FileShareResultVO;
import com.fy.pojo.vo.user.LoginUserVO;
import com.fy.service.FileShareService;
import com.fy.utils.result.PageResult;
import com.fy.utils.result.Result;
import lombok.extern.slf4j.Slf4j;
import com.fy.common.constants.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@Slf4j
@RestController
@RequestMapping("/share")
public class ShareController extends BaseController {

    @Autowired
    private FileShareService fileShareService;

    /**文件分享
     *
     * @param shareFileDTO
     * @return
     */
    @PostMapping("/shareFile")
    @GlobalInterceptor
    public Result shareFile(HttpSession httpSession, FileShareDTO shareFileDTO){
        log.info("shareFile:{}",shareFileDTO);
        LoginUserVO loginUserVO= (LoginUserVO) httpSession.getAttribute(Constants.SESSION_KEY);
        FileShareResultVO fileShareResultVO= fileShareService.fileShare(shareFileDTO,loginUserVO);
        log.info("kkkkkkkk:{}",shareFileDTO);
        return Result.success(fileShareResultVO);
    }

    @PostMapping("/loadShareList")
    @GlobalInterceptor(checkParams = true)
    public Result<PageResult> loadShareList(HttpSession httpSession,String pageNo,String pageSize) {
        LoginUserVO loginUserVO= (LoginUserVO) httpSession.getAttribute(Constants.SESSION_KEY);
        log.info("loadShareListkkkk:{},{}", pageNo,pageSize);
        PageResult pageResult=fileShareService.fileSharePageQuery(loginUserVO,pageNo,pageSize);
        log.info("返回数据封装:{}",pageResult);
        //return Result.success(pageResult);
        return Result.success(pageResult);
    }

    /**取消分享
     *
     * @param shareIds
     * @return
     */
    @PostMapping("/cancelShare")
    @GlobalInterceptor
    public Result cancelShare(String shareIds){
        log.info("cancelShare:{}",shareIds);
        fileShareService.cancelShare(shareIds);
        return Result.success();
    }

}
